package cn.com.xy.sms.sdk.ui.popu.util;

import android.app.Activity;
import android.view.ViewGroup;
import cn.com.xy.sms.sdk.Iservice.XyCallBack;
import cn.com.xy.sms.sdk.smsmessage.BusinessSmsMessage;
import cn.com.xy.sms.sdk.ui.R;
import cn.com.xy.sms.sdk.ui.popu.part.BubbleAirBody;
import cn.com.xy.sms.sdk.ui.popu.part.BubbleBodyCallsMessage;
import cn.com.xy.sms.sdk.ui.popu.part.BubbleBottomTwo;
import cn.com.xy.sms.sdk.ui.popu.part.BubbleBottomTwoCMCC;
import cn.com.xy.sms.sdk.ui.popu.part.BubbleCodeHead;
import cn.com.xy.sms.sdk.ui.popu.part.BubbleCodeHeadCMCC;
import cn.com.xy.sms.sdk.ui.popu.part.BubbleGeneralTwoTextBody;
import cn.com.xy.sms.sdk.ui.popu.part.BubbleGeneralTwoTextBodyCMCC;
import cn.com.xy.sms.sdk.ui.popu.part.BubbleHintTextBody;
import cn.com.xy.sms.sdk.ui.popu.part.BubbleHorizTableBody;
import cn.com.xy.sms.sdk.ui.popu.part.BubbleProgressBarTable;
import cn.com.xy.sms.sdk.ui.popu.part.BubbleTrainBody;
import cn.com.xy.sms.sdk.ui.popu.part.BubbleVerificationTextBody;
import cn.com.xy.sms.sdk.ui.popu.part.CardBodySplit;
import cn.com.xy.sms.sdk.ui.popu.part.UIPart;

public class ViewMangerImpl extends ViewManger {
    
    /*
     * 101-499 for head;501~899 for body;901~999 for button Don't set in
     * multiples of 100 number
     */
    private final static Integer VIEW_PART_ID[] = { 
        ViewPartId.PART_HEAD_CODE, 
        ViewPartId.PART_BOTTOM_TWO_BUTTON, 
        ViewPartId.PART_CARD_BODY_SPLIT,
        ViewPartId.PART_BODY_TRAIN_TABLE, 
        ViewPartId.PART_BODY_AIR_TABLE, 
        ViewPartId.PART_VERIFICATION_SMS_TEXT,
        ViewPartId.PART_CALL_MESSAGE_BODY, 
        ViewPartId.PART_BODY_TWO_TEXT,
        ViewPartId.PART_BODY_HORIZ_TABLE_SEC,
        ViewPartId.PART_BODY_HINT_TEXT,
        ViewPartId.PART_HEAD_SELECTED,
        ViewPartId.PART_HEAD_CODE_CMCC,
        ViewPartId.PART_BODY_ORIGINAL_TEXT_CMCC,
        ViewPartId.PART_BODY_ABLE_SEC_CMCC,
        ViewPartId.PART_BOTTOM_TWO_BUTTON_CMCC,

    }; // all
                                                                                                                   // part
            
    public Integer[] getViewPartIdArr(){
        return VIEW_PART_ID;
    }

    /**
     * Head part
     * 
     * @param context
     * @param message
     * @param xyCallBack
     * @param root
     * @param partId
     * @return
     * @throws Exception
     */
    private UIPart getHeadUIPartByPartId(Activity context, BusinessSmsMessage message, XyCallBack xyCallBack,
            ViewGroup root, int partId) throws Exception {
        UIPart part = null;
        switch (partId) {
            case ViewPartId.PART_HEAD_SELECTED:
            case ViewPartId.PART_HEAD_CODE:
                part = new BubbleCodeHead(context, message, xyCallBack, R.layout.duoqu_title_head, root, partId);
                break;
            case ViewPartId.PART_HEAD_CODE_CMCC:
                part = new BubbleCodeHeadCMCC(context, message, xyCallBack, R.layout.duoqu_title_head_cmcc, root, partId);
                break;
            default:
                break;
        }
        return part;
    }
    
    /**
     * Body part
     * 
     * @param context
     * @param message
     * @param xyCallBack
     * @param root
     * @param partId
     * @return
     * @throws Exception
     */
    private UIPart getBodyUIPartByPartId(Activity context, BusinessSmsMessage message, XyCallBack xyCallBack,
            ViewGroup root, int partId) throws Exception {
        UIPart part = null;
        switch (partId) {
            case ViewPartId.PART_CARD_BODY_SPLIT:
                part = new CardBodySplit(context, message, xyCallBack, R.layout.duoqu_card_bubble_split, root, partId);
                break;
            case ViewPartId.PART_BODY_TRAIN_TABLE:
                part = new BubbleTrainBody(context, message, xyCallBack, R.layout.duoqu_train_body, root, partId);
                break;
            case ViewPartId.PART_BODY_AIR_TABLE:
                part = new BubbleAirBody(context, message, xyCallBack, R.layout.duoqu_air_body, root, partId);
                break; 
            case ViewPartId.PART_VERIFICATION_SMS_TEXT:
                part = new BubbleVerificationTextBody(context, message, xyCallBack, R.layout.duoqu_sms_verification_text, root,
                        partId);
                break;
            case ViewPartId.PART_CALL_MESSAGE_BODY:
                part = new BubbleBodyCallsMessage(context, message, xyCallBack, R.layout.duoqu_bubble_body_callsmessage,
                        root, partId);
                break;
            case ViewPartId.PART_BODY_HORIZ_TABLE_SEC:
                part = new BubbleHorizTableBody(context, message, xyCallBack, R.layout.duoqu_horizl_table_body, root, partId);
                break;
            case ViewPartId.PART_BODY_TWO_TEXT:
                part = new BubbleGeneralTwoTextBody(context, message, xyCallBack, R.layout.duoqu_bubble_two_text_body, root, partId);
                break;
            case ViewPartId.PART_BODY_HINT_TEXT:
                part = new BubbleHintTextBody(context, message, xyCallBack, R.layout.duoqu_bubble_hint_text_body, root, partId);
                break;
            case ViewPartId.PART_BODY_ORIGINAL_TEXT_CMCC:
                part = new BubbleGeneralTwoTextBodyCMCC(context, message, xyCallBack, R.layout.duoqu_bubble_two_text_body_cmcc, root, partId);
                break;
            case ViewPartId.PART_BODY_ABLE_SEC_CMCC:
                part = new BubbleProgressBarTable(context, message, xyCallBack, R.layout.duoqu_bubble_body_progressbar_table, root, partId);
                break;
            default:
                break;
        }
        return part;
    }
    
    /**
     * Foot part
     * 
     * @param context
     * @param message
     * @param xyCallBack
     * @param root
     * @param partId
     * @return
     * @throws Exception
     */
    private UIPart getFootUIPartByPartId(Activity context, BusinessSmsMessage message, XyCallBack xyCallBack,
            ViewGroup root, int partId) throws Exception {
        UIPart part = null;
        switch (partId) {
            case ViewPartId.PART_BOTTOM_TWO_BUTTON:
                part = new BubbleBottomTwo(context, message, xyCallBack, R.layout.duoqu_bubble_bottom_two, root,
                        partId);
                break;
            case ViewPartId.PART_BOTTOM_TWO_BUTTON_CMCC:
                part = new BubbleBottomTwoCMCC(context, message, xyCallBack, R.layout.duoqu_bubble_bottom_two_cmcc, root,
                        partId);
                break;
            default:
                break;
        }
        return part;
    }
    
    public UIPart getUIPartByPartId(Activity context, BusinessSmsMessage message, XyCallBack xyCallBack,
            ViewGroup root, int partId) throws Exception {
        UIPart part = null;
        if (partId < 500) {
            part = getHeadUIPartByPartId(context, message, xyCallBack, root, partId);
        } else if (partId < 900) {
            part = getBodyUIPartByPartId(context, message, xyCallBack, root, partId);
            
        } else if (partId >= 900) {
            part = getFootUIPartByPartId(context, message, xyCallBack, root, partId);
        }
        return part;
    }
}
